import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JPanel;
import javax.swing.JTabbedPane;

public class MenuTab {

	private String[] tabs;
	private Container[] conTabs;
	private GridBagLayout[] gbl_tabs;
	private JPanel[] panTabs;

	public void addComponent(String ContainerName, Component c, int x, int y,
			int width, int height, double weightx, double weighty) {
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.BOTH;
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridheight = height;
		gbc.gridwidth = width;
		gbc.weightx = weightx;
		gbc.weighty = weighty;
		gbl_tabs[getIndex(ContainerName)].setConstraints(c, gbc);
		conTabs[getIndex(ContainerName)].add(c);
	}

	private void addComponent(Container cont, GridBagLayout gbl, Component c,
			int x, int y, int width, int height, double weightx, double weighty) {

		GridBagConstraints gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.BOTH;
		gbc.gridx = x;
		gbc.gridy = y;
		gbc.gridheight = height;
		gbc.gridwidth = width;
		gbc.weightx = weightx;
		gbc.weighty = weighty;
		gbl.setConstraints(c, gbc);
		cont.add(c);
	}

	private int getIndex(String name) {
		for (int i = 0; i < tabs.length; i++) {
			if (tabs[i].equals(name)) {
				return i;
			}
		}
		return -1;
	}
	public MenuTab(Container conMain, String[] tabsName,
			String[] panTabsLayout, GridBagLayout layoutGlobal, int x,
			int y, int width, int height, double weightx, double weighty)
			throws Exception {
		JTabbedPane tab_menu = new JTabbedPane();

		tabs = new String[tabsName.length];
		tabs = tabsName;
		
		conTabs = new Container[tabsName.length]; // Container in den Tabs
		gbl_tabs = new GridBagLayout[tabsName.length]; // GridBagLayout in den
														// Tabs
		panTabs = new JPanel[tabsName.length]; // Buffervaraible um die
												// Componenten links oben zu
												// Zentrieren

		for (int i = 0; i < tabsName.length; i++) {
			conTabs[i] = new Container();
			gbl_tabs[i] = new GridBagLayout();
			conTabs[i].setLayout(gbl_tabs[i]);
			panTabs[i] = new JPanel(new BorderLayout());
			panTabs[i].add(conTabs[i], panTabsLayout[i]);
			tab_menu.addTab(tabs[i], panTabs[i]);
		}
		
		this.addComponent(conMain, layoutGlobal, tab_menu, x, y, width, height, weightx, weighty);
	}
}
